import Dashboard from '@/views/Dashboard.vue';
import ExpertExtraction from '@/views/ExpertExtraction.vue';
import ExpertTable from '@/views/ExpertTable.vue';
import Login from '@/views/Login.vue';
import Logout from '@/views/Logout.vue';
import ProfessionTable from '@/views/ProfessionTable.vue';
import ProjectTable from '@/views/ProjectTable.vue';
import User from '@/views/User.vue';
import { createRouter, createWebHistory } from 'vue-router';

const routes = [  
  { path: '/login', component: Login },
  { path: '/logout', component: Logout },
  { path: '/dashboard', component: Dashboard },
  { path: '/experts', component: ExpertTable },
  { path: '/projects', component: ProjectTable },
  { path: '/professions', component: ProfessionTable },
  { path: '/expert-extractions', component: ExpertExtraction },
  { path: '/users', component: User }
];

const router = createRouter({
  history: createWebHistory("expertextractionwebsite"), // 设置路由前缀为 "/app"
  routes
});

// 全局前置守卫
router.beforeEach((to, from, next) => {
  const routeExists = router.getRoutes().some(route => route.path === to.path);
  if (!routeExists) {
    next('/expert-extractions'); // 跳转到expert-extractions页面
  } else {
    next();
  }
});
export default router;